﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAL
{
    public class WebNews
    {
        public static void insert(WebNewsEntity webnewsEnt)
        {
            DbHelper.ExecuteNonQuery("p_WebNews_insert",
                webnewsEnt.Text,
                webnewsEnt.Url,
                webnewsEnt.IsShow,
                webnewsEnt.AdminId
            );
        }

        public static void update(WebNewsEntity webnewsEnt)
        {
            DbHelper.ExecuteNonQuery("p_WebNews_update",
                webnewsEnt.Id,
                webnewsEnt.Text,
                webnewsEnt.Url,
                webnewsEnt.IsShow
            );
        }
        public static WebNewsEntity getById(int id)
        {
            DataRow dr = DbHelper.ExecuteDataRow("p_WebNews_getById", id);
            WebNewsEntity wn = new WebNewsEntity();
            if (dr != null)
            {
                wn.Id = int.Parse(dr["Id"].ToString());
                wn.Text = dr["Text"].ToString();
                wn.Url = dr["Url"].ToString();
                wn.IsShow = bool.Parse(dr["IsShow"].ToString());
                wn.AdminId = int.Parse(dr["AdminId"].ToString());
                wn.InputDt = Convert.ToDateTime(dr["inputDt"]);
            }
            return wn;
        }
        public static void delete(int Id)
        {
            DbHelper.ExecuteNonQuery("p_webNews_delete", Id);
        }
    }
}
